#! /usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023-04-17 22:07
# @Author  : wsh
# @File    : users_params.py
from typing import Optional

from pydantic import BaseModel, Field

from .roles_params import RoleNameEnum


class UserLoginParam(BaseModel):  # 用户登录参数
    username: str = Field(..., min_length=3, max_length=16, title="用户名")
    password: str = Field(..., min_length=6, max_length=16, title="密码")
    code: str = Field(..., title="验证码")
    role_name: RoleNameEnum = Field(..., title="角色名称")


# 用户注册参数
class UserRegisterParam(BaseModel):
    company_code: str = Field(max_length=10, title="机构代码")
    user_name: str = Field(..., min_length=3, max_length=16, title="用户名")
    role_name: str = Field(..., min_length=3, max_length=16, title="角色")
    true_name: str = Field(max_length=15, title="真实姓名")
    password: str = Field(..., min_length=6, max_length=16, title="密码")
    depart_name: str = Field(title="所属部门")
    job_name: str = Field(max_length=15, title="所属岗位")
    email: str = Field(title="邮箱")
    email_code: str = Field(title="邮箱验证码")
    phone: str = Field(title="手机")
    remark: str = Field(title="备注")


class UserInfoParam(BaseModel):
    user_name: str = Field(max_length=15, title="用户名")
    role_name: str = Field(..., title="角色名称")
    company_name: str = Field(..., title='隶属公司名称')
    belong_post: str = Field(max_length=50, title="所属部门")
    job_name: str = Field(max_length=15, title="所在岗位")
    true_name: str = Field(max_length=15, title="真实姓名")
    group_id: int = Field(title="用户组ID")
    phone: str = Field(default="15904290573", max_length=11, title="用户电话", regex=r'^1[3-9]\d{9}$')
    email: str = Field(max_length=30, title="用户邮箱", regex=r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$')
    remark: str = Field(default="", title="备注")


class RegUserParam(BaseModel):
    user_name: str = Field(max_length=15, title="用户名")
    user_pwd: str = Field(max_length=25, title="密码")
    role_name: str = Field(..., title="角色名称")
    company_name: str = Field(..., title='隶属公司名称')
    belong_post: str = Field(max_length=50, title="所属部门")
    job_name: str = Field(max_length=15, title="所在岗位")
    true_name: str = Field(max_length=15, title="真实姓名")
    group_id: int = Field(title="用户组ID")
    phone: str = Field(default="15904290573", max_length=11, title="用户电话", regex=r'^1[3-9]\d{9}$')
    email: str = Field(max_length=30, title="用户邮箱", regex=r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$')
    remark: str = Field(default="", title="备注")


class PasswordByEmailParam(BaseModel):
    email_code: str = Field(title="邮箱验证码")
    email: str = Field(title="邮箱")
    user_pwd: str = Field(title="密码")


class EmailValidateParam(BaseModel):
    email_code: str = Field(title="邮箱验证码")
    email: str = Field(title="邮箱")


class PasswordByLogin(BaseModel):
    user_id: int = Field(title="用户ID")
    old_password: str = Field(title="旧密码")
    new_password: str = Field(title="新密码")


class ActivateParam(BaseModel):
    activate_user_id: int = Field(title="待激活用户ID")


class Email(BaseModel):
    email: str = Field(title="邮箱")


class UserID(BaseModel):
    user_id: int = Field(title="用户ID")


class ProjID(BaseModel):
    proj_id: int = Field(title="工程ID")


class UserInfoUpdateParam(BaseModel):
    user_id: int = Field(title="用户ID")
    user_name: str = Field(max_length=15, title="用户名")
    job_name: str = Field(max_length=15, title="所在岗位")
    true_name: str = Field(max_length=15, title="真实姓名")
    phone: str = Field(default="15904290573", max_length=11, title="用户电话", regex=r'^1[3-9]\d{9}$')
    remark: str = Field(default="", title="备注")


class ProjectParam(BaseModel):
    project_name: str = Field(title="用户ID")
    create_user: int = Field(title="用户名")
    remark: str = Field(title="所在岗位")


class Activate_param(BaseModel):
    activate_user_id: int = Field(title="用户激活参数")
    neither_activate: int = Field(title="是否同意激活")
